<?php
    require('db_connection.php');
    $today = date("Y-m-d H:i.s",time());

    $query = "SELECT * FROM tblcirculation WHERE status='reserved'";
    $result= mysql_query($query);
    while ($row = mysql_fetch_array($result))
    {
        $dateExpire = $row['dateExpire'];
        $materialID = $row['materialID'];
        $userID = $row['userID'];
        if($today == $dateExpire || $today > $dateExpire )
        {
             $query4 = "DELETE FROM tblcirculation WHERE materialID like '$materialID'";
             $result4 = mysql_query($query4);
             //echo $query3;
             $userID = $_COOKIE['user'];
             //confirm_reservation($materialID, $userID, $libraryNo,$reserve_date,$expire_date);
            $query5 = "SELECT * FROM tblclient WHERE userID ='$userID'";
            $result5= mysql_query($query5);
            while ($row = mysql_fetch_array($result5))
            {
              $warning = $row['warning'];
            }
            if($warning == 3)
            {

            }
            else
            {
              $warning++;
            }
            $query6 = "UPDATE tblclient SET warning=$warning,stat='3' WHERE userID=$userID";
            $result6 = mysql_query($query6);

        }
        elseif ($today < $dateExpire)
        {
            //echo "<script>alert('This is reserved.')</script>";
            //echo "<script>history.back();</script>";
        }
    }

?>
